<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
    extension-element-prefixes="redirect">
<xsl:output method="html" indent="yes" encoding="US-ASCII"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:param name="output.dir" select="'.'"/>
<xsl:param name="TITLE">Unit Test Results.</xsl:param>

<xsl:template match="testsuites">
    <redirect:write file="{$output.dir}/unit-test-summary.txt">
        <xsl:apply-templates select="." mode="overview.packages"/>
    </redirect:write>
</xsl:template>

<xsl:template match="testsuites" mode="overview.packages">
  <xsl:variable name="testCount" select="sum(testsuite/@tests)"/> <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/> <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/> <xsl:variable name="timeCount" select="sum(testsuite/@time)"/> <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>unit.test.summary=Tests <xsl:value-of select="$testCount"/> Failures <xsl:value-of select="$failureCount"/> Errors <xsl:value-of select="$errorCount"/> Success rate <xsl:call-template name="display-percent"> <xsl:with-param name="value" select="$successRate"/> </xsl:call-template> Time <xsl:call-template name="display-time"> <xsl:with-param name="value" select="$timeCount"/> </xsl:call-template>
</xsl:template>

<xsl:template name="display-time">
    <xsl:param name="value"/>
    <xsl:value-of select="format-number($value,'0.000')"/>
</xsl:template>

<xsl:template name="display-percent">
    <xsl:param name="value"/>
    <xsl:value-of select="format-number($value,'0.00%')"/>
</xsl:template>
</xsl:stylesheet>
